package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.*;
import com.ruoyi.system.service.ISchoolClassesjkService;
import com.ruoyi.system.service.IShCourseTeacherService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/classesjk")
public class SchoolClassesjkController extends BaseController {
    @Autowired
    private ISchoolClassesjkService schoolClassesjkService;

    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private IShCourseTeacherService shCourseTeacherService;

    /**
     * 查询班级信息列表
     */
    @RequiresPermissions("business:classesjk:list")
    @GetMapping("/list")
    public TableDataInfo list(SchoolClassesjk schoolClasses)
    {
        startPage();
        List<SchoolClassesjk> list = schoolClassesjkService.selectSchoolClassesjkList(schoolClasses);
        return getDataTable(list);
    }

    /**
     * 导出培训信息列表
     */
    @RequiresPermissions("business:classesjk:export")
    @Log(title = "培训信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, SchoolClassesjk schoolClasses)
    {
        List<SchoolClassesjk> list = schoolClassesjkService.selectSchoolClassesjkList(schoolClasses);
        for (SchoolClassesjk obj:list) {
            SysDept sysDept = sysDeptService.selectDeptById(obj.getSchoolId());
            ShCourseTeacher teacherJx = shCourseTeacherService.selectShCourseTeacherById(obj.getJxteacherId());
            obj.setSchoolName(sysDept.getDeptName());
            obj.setJxusername(teacherJx.getTeacherName());
        }
        ExcelUtil<SchoolClassesjk> util = new ExcelUtil<SchoolClassesjk>(SchoolClassesjk.class);
        util.exportExcel(response, list, "培训信息");
    }

    /**
     * 获取培训信息详细信息
     */
    @RequiresPermissions("business:classesjk:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(schoolClassesjkService.selectSchoolClassesjkById(id));
    }

    /**
     * 新增培训信息
     */
    @RequiresPermissions("business:classesjk:add")
    @Log(title = "培训信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchoolClassesjk schoolClasses)
    {
        return toAjax(schoolClassesjkService.insertSchoolClassesjk(schoolClasses));
    }

    /**
     * 修改培训信息
     */
    @RequiresPermissions("business:classesjk:edit")
    @Log(title = "培训信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchoolClassesjk schoolClasses)
    {
        return toAjax(schoolClassesjkService.updateSchoolClassesjk(schoolClasses));
    }

    /**
     * 删除班级信息
     */
    @RequiresPermissions("business:classesjk:remove")
    @Log(title = "培训信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        schoolClassesjkService.checkCanDelete(ids);
        return toAjax(schoolClassesjkService.deleteSchoolClassesjkByIds(ids));
    }
}
